package Server;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Log {
	String path;
	SimpleDateFormat dateFormat;
	Calendar calendar;

	public Log() {
		path = "log/log.txt";
		calendar = Calendar.getInstance();
		dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		

	}

	public void log(String user, String message) {
		BufferedWriter out = null;
		try {
			out = new BufferedWriter(new FileWriter(path, true));
		} catch (IOException e) {
			e.printStackTrace();
		}

		if (out == null) {
			System.out.println("Unable to access log file.");
		} else {

			try {

				out.write(user + " " + message + dateFormat.format(calendar.getTime()));
				out.newLine();
				out.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
